package com.flyme.module.base.provider.controller;

import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.module.base.client.api.SysExamtypeRemoteService;
import com.flyme.module.base.client.entity.SysExamtype;
import com.flyme.module.base.provider.service.SysExamtypeService;
import com.flyme.module.file.client.entity.SysCourse;
import com.flyme.module.file.client.entity.SysCourseType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 考试分类管理
 * @author zyh
 * @date 2020-7-8
 */
@Api(tags = "考试分类")
@RestController
public class SysExamtypeController extends BaseController<SysExamtypeService, SysExamtype> implements SysExamtypeRemoteService {

    @ApiOperation(value = "获取考试分类2")
    @Override
    public ResultBody selectTypeList() {
        return ResultBody.success(bizService.list());
    }

    @ApiOperation(value = "获取考试分类")
    @Override
    public ResultBody selectTreeData( @RequestParam(value = "title",required=false) String title) {
        CriteriaQuery qw = new CriteriaQuery<Map<String, Object>>();
        qw.select("*");
        qw.orderByAsc("sortOrder");
        qw.like("examTypeName",title);
        List list = bizService.listMaps(qw);
        return ResultBody.success(toCascader(list));
    }

    @ApiOperation(value = "获取考试分类")
    @Override
    public ResultBody selectTreeData2( @RequestParam(value = "title",required=false) String title) {
        CriteriaQuery qw = new CriteriaQuery<Map<String, Object>>();
        qw.select("*, id value,examTypeName title");
        qw.orderByAsc("sortOrder");
        qw.like("examTypeName",title);
        List list = bizService.listMaps(qw);
        return ResultBody.success(list);
    }

    @ApiOperation(value = "添加考试分类", notes = "添加考试分类")
    @Override
    public ResultBody addExamType(@ModelAttribute(value = "examType") SysExamtype examType) {
        boolean result = bizService.addExamType(examType);
        return ResultBody.success(result);
    }

    @ApiOperation(value = "编辑考试分类", notes = "编辑考试分类")
    @Override
    public ResultBody edit(SysExamtype examType) {
        boolean result= bizService.updateExamType(examType);
        return ResultBody.success(result);
    }

    @ApiOperation(value = "删除考试分类", notes = "删除考试分类")
    @Override
    public ResultBody delById(@PathVariable Long examTypeId) {
        return bizService.delById(examTypeId);
    }

    @ApiOperation(value = "删除考试分类", notes = "删除考试分类")
    @Override
    public ResultBody delById2(@PathVariable Long id) {
        return bizService.delById(id);
    }


}
